package com.open.demo.span

import android.os.Bundle
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.open.demo.R

/**
 * TextView Span Demo.
 *
 * @Author: hailong.qiu hailong.qiu@xgimi.com
 * @Maintainer: hailong.qiu hailong.qiu@xgimi.com
 * @Date: 2021/7/2
 * @Copyright: 2021 www.xgimi.com Inc. All rights reserved.
 */
class SpanActivity: AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_span_layout)
        val drawable = getDrawable(R.drawable.ic_metal_rem_con_back_key)
        if (null != drawable) {
//            span_tv.lineHeight
            drawable?.setBounds(0, 0, 40, 40)
//            val imageSpan = NewImageSpan(drawable)
            val imageSpan = NewImageSpan(drawable)
            val imageSpan2 = NewImageSpan(drawable)
            //
            val str1 = getString(R.string.setup_metal_rem_focus_deatil_text1)
            val str2 = getString(R.string.setup_metal_rem_focus_deatil_text2)
            val str3 = getString(R.string.setup_metal_rem_focus_deatil_text3)
            val spanStringBuilder = SpannableStringBuilder("$str1$str2$str3")
            val start1 = str1.indexOf(SPLIT_STR)
            val end1 = start1 + SPLIT_STR.length
            val start2 = str1.length + str2.indexOf(SPLIT_STR)
            val end2 = start2 + SPLIT_STR.length
            spanStringBuilder.setSpan(imageSpan, start1, end1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
            spanStringBuilder.setSpan(imageSpan2, start2, end2, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
            val span_tv = findViewById<TextView>(R.id.span_tv)
            span_tv.text = spanStringBuilder
        }
    }

    companion object {
        const val SPLIT_STR = "对焦键"
    }

}